// GEO pchart

function PieChart(panelID, pchartID, pchartHeaderID, listPanelID, listBoxID, listHeaderID, restoreID, minimizeID){

	 this.panelID = panelID;
	 this.pchartID = pchartID;
	 this.pchartHeaderID = pchartHeaderID;
	 this.listBoxID = listBoxID;
	 this.listHeaderID = listHeaderID;
	 this.listPanelID = listPanelID;
	 this.restoreButtonID = restoreID;
	 this.minimizeButtonID = minimizeID;
 
	 this.SetPieChartOptions(); 
}

PieChart.prototype.SetPieChartOptions = function(){

	this.pchartOptions = {}; 
	this.pchartOptions['is3D'] = true;
	this.pchartOptions['backgroundColor'] = '#e9f7f9';
	this.pchartOptions['width'] = 400;
	this.pchartOptions['height'] = 385;
	this.pchartOptions['enableTooltip'] = false;
	this.pchartOptions['fontSize'] = 9;
 
}

PieChart.prototype.SetBlankPieChartOptions = function(){

	this.bpchartOptions = {}; 
	this.bpchartOptions['is3D'] = true;
	this.bpchartOptions['backgroundColor'] = '#e9f7f9';
	this.bpchartOptions['width'] = 400;
	this.bpchartOptions['height'] = 385;
	this.bpchartOptions['enableTooltip'] = false;
	this.pchartOptions['fontSize'] = 9;
	
}

PieChart.prototype.DrawBlankPieChart = function(){

	var data = new google.visualization.DataTable();

	data.addColumn('string', 'Taxa');
	data.addColumn('number', 'GCN Species');
	data.addRows(1); 
	
	data.setValue(0,0,'All');
	data.setValue(0,1,100); 		
	var chart = new google.visualization.PieChart(document.getElementById(this.pchartID));
	chart.draw(data, this.bpchartOptions);

}

PieChart.prototype.DrawPieChart = function(data){

    var chart = new google.visualization.PieChart(document.getElementById(this.pchartID));
	var totalSpecies = 0;
	var string = '';
	var n = data.getNumberOfRows();
	for(var i=0; i<n; i++){
		totalSpecies += data.getValue(i,1);
		 
	}
	
    google.visualization.events.addListener(chart, 'select', function(e) {    
	   var xy = chart.getSelection();
	   if(xy.length > 0){
			var item = xy[0];
			var row = item.row;
			var column = 0;
			var dataItem = data.getValue(row, column);  
		
			piechart_onclick(dataItem);
	
		} 
    });
 
	google.visualization.events.addListener(chart, 'onmouseover', function(e) { 

					var row = e['row'];					
					var taxa = data.getValue(row, 0);						
					var speciesCount = data.getValue(row, 1);
					var percentageCount = speciesCount*100;
					percentageCount /= totalSpecies;
					var text = taxa  + ' ' + speciesCount + ' (' + percentageCount.toFixed(2) + '%)';
					
					piechart_mouseover(text);
				 
		  });
		  
		  google.visualization.events.addListener(chart, 'onmouseout', function(e) { 	
				piechart_mouseout();
					
		  });
		 	
		chart.draw(data, this.pchartOptions);
}


PieChart.prototype.MinimizePieChart = function(){
	$('#' + this.panelID).hide();

	$('#' + this.restoreButtonID).show();
}

PieChart.prototype.RestorePieChart = function(){

	$('#' + this.panelID).show();
	$('#' + this.restoreButtonID).hide();
 
}

PieChart.prototype.MinimizeList = function(){
	$('#' + this.listPanelID).hide();
}

PieChart.prototype.RestoreList = function(){
	$('#' + this.listPanelID).show();
}
		
 
 


 